"""
_*_ : utf-8 _*_ 
@Time: 2023/10/31 21:10
@Author: LWK
@File: 060_urllib_post百度翻译详细翻译
@Project: demo01
"""
import json
import urllib.request
import urllib.parse

url = 'https://fanyi.baidu.com/v2transapi?from=srp&to=zh'

headers = {
    # 'Accept': '*/*',
    # 'Accept-Encoding': 'gzip, deflate, br',
    # 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    # 'Acs-Token': '1698757843043_1698757847882_pY6EkyJFsom694DO2QhkXc3n+wwmWMVqJjQSHgvFUL+qivGsRJvKB'
    #              '/j0nMEe08Ph30XPhA191zIe+tCGpPNJd+6Deq7tmNi7WDhmbN016cxPep73c8'
    #              '+YOZzYK4sY97Iu3FO9wIKqVEcwVJWJtAzpWNBViM4VJHts6YmcWAhul41YqjKWMGu'
    #              '+LgZuWp1tzau2JxYKqKD6dUlADjcWGZNApg35RwOJTDESEvhE3T3T5VU6AU7TOaRYDo1P9OY7D2OnfvJlcx5A'
    #              '/ISj3NJRUqnIVxhMWEdf+lDaGmDZIdn6OfxmvToTzkVuAaxerV7d32yGuL5ojUDwbQ54I4kLLL'
    #              '+DJW28Pe60dKjyu40N7k8CKDSU2qzG5mgtmLhSGYN6nWw2yStaIAdZE/w2qtEReWNPfbPyk3b/K9C5kSHuczf92J8b1LVXyfIJs'
    #              '+wWRebIg7wq1VtJbVA4bmh2e/81nxMd4na0PAxxcRLIRXGkc'
    #              '+BLAe9oG3FF46qjOB4jNJ7FZwqOcWibgABhCQJrBt6F156Enrv7t6R+LmWVcKYwNJQAic4=',
    # 'Connection': 'keep-alive',
    # 'Content-Length': '152',
    # 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': 'BAIDUID=F1CB82512F626E5BB8EC0A85AFD49E3A:FG=1; BIDUPSID=F1CB82512F626E5BB8EC0A85AFD49E3A; PSTM=1693642461; BDUSS=TNGVjUzTXBBSkdmbS1aYmdKLVpDdXI3SG5NWmtmdn5zOTlVeDh1eWxTNG43QzlsSVFBQUFBJCQAAAAAAAAAAAEAAABTJZLP087OqtPOz7e94su1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACdfCGUnXwhlW; BDUSS_BFESS=TNGVjUzTXBBSkdmbS1aYmdKLVpDdXI3SG5NWmtmdn5zOTlVeDh1eWxTNG43QzlsSVFBQUFBJCQAAAAAAAAAAAEAAABTJZLP087OqtPOz7e94su1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACdfCGUnXwhlW; H_WISE_SIDS=234020_110085_268593_269904_271172_270102_275170_276533_277030_277355_277640_275733_277997_259642_278056_278392_278575_278704_278514_278388_279021_279044_279357_279613_279286_279711_279998_280302_280375_278415_276438_280619_280809_280106_280557_278791_280636_203517_267170_281037_280167_281236_277970_281148_281368_279202; MCITY=-224%3A289%3A; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1698756808; APPGUIDE_10_6_6=1; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1698757843; ab_sr=1.0.1_N2Q1YmVhMjc2Y2JhMmJhYTcxN2Q0MjIyZWUxY2IyMzQ5NThiNWFkYTUyMDljYjdkMmQ4MGFmZmJhNWYzM2QzOGI5NTU4NzRlNjFkNmZiN2I4OGUwNDJiMzE1MDRjZTcwMzI2YmE0YmYyMTY0OWVhMGViNjhjMzcyOTA5YmRhY2E2ZTlkMTcyMjllZGVkOTQzNTczMDIwYjEzNjc2OTZmZjlmNGZmMmYzNjU0NDg5YzIzN2U3MzlmZjEwYWI2NGZj; BA_HECTOR=agag8l04812la4a12081858j1ik1vum1r; BAIDUID_BFESS=F1CB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0x0bOte-bQXH_E5bj2qRI8oC_-3q; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; H_PS_PSSID=39447_39396_39530_39418_39438_39526_39497_26350_39564'
    # 'Host': 'fanyi.baidu.com',
    # 'Origin': 'https://fanyi.baidu.com',
    # 'Referer': 'https://fanyi.baidu.com/?aldtype=16047',
    # 'Sec-Fetch-Dest': 'empty',
    # 'Sec-Fetch-Mode': 'cors',
    # 'Sec-Fetch-Site': 'same-origin',
    # 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.76',
    # 'X-Requested-With': 'XMLHttpRequest',
    # 'sec-ch-ua': '"Chromium";v="118", "Microsoft Edge";v="118", "Not=A?Brand";v="99"',
    # 'sec-ch-ua-mobile': '?0',
    # 'sec-ch-ua-platform': 'macOS',
}

params = {
    'from': 'srp',
    'to': 'zh',
    'query': 'love',
    'transtype': 'realtime',
    'simple_means_flag': '3',
    'sign': '198772.518981',
    'token': '4f93df2c3774464cca07875b208a7da6',
    'domain': 'common'
}

data = urllib.parse.urlencode(params).encode('utf-8')

# post的请求参数，是不会拼接在url后面的，而是需要放在请求对象定制的参数中
req = urllib.request.Request(url, data, headers)

# 模拟浏览器向服务器发送请求
res = urllib.request.urlopen(req)

# 获取响应的数据
content = res.read().decode('utf-8')

obj = json.loads(content)

print(obj)
